// Entity全局管理器
class EntityManager {
    private static instance: EntityManager;
    private createdEntities: any[] = [];

    private constructor() {}

    public static getInstance(): EntityManager {
        if (!EntityManager.instance) {
            EntityManager.instance = new EntityManager();
        }
        return EntityManager.instance;
    }

    // 添加Entity
    public addEntity(entity: any): void {
        this.createdEntities.push(entity);
        console.log(`Entity已添加到管理器，当前数量: ${this.createdEntities.length}`);
    }

    // 移除指定的Entity
    public removeEntity(entity: any, viewer: any): void {
        const index = this.createdEntities.indexOf(entity);
        if (index > -1) {
            viewer.entities.remove(entity);
            this.createdEntities.splice(index, 1);
            console.log(`Entity已从管理器移除，剩余数量: ${this.createdEntities.length}`);
        }
    }

    // 清除所有管理的Entity
    public clearAllEntities(viewer: any): void {
        console.log(`开始清除 ${this.createdEntities.length} 个Entity`);
        this.createdEntities.forEach(entity => {
            viewer.entities.remove(entity);
        });
        this.createdEntities = [];
        console.log('所有管理的Entity已清除');
    }

    // 获取当前管理的Entity数量
    public getCount(): number {
        return this.createdEntities.length;
    }

    // 获取所有管理的Entity
    public getAllEntities(): any[] {
        return [...this.createdEntities];
    }
}

export default EntityManager;
